package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppMessageRecord;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统消息
 */
@Repository
public class AfterMessageRecordDao extends BaseDao<AppMessageRecord> {

    /**
     * 查询列表
     */
    public List<AppMessageRecord> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_message_record where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("type"))) {
            sbStr.append(" and type = ? ");
            paramList.add(paraMap.get("type"));
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppMessageRecord.class,splitPage);
    }


    /**
     * 详情
     */
    public AppMessageRecord get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_message_record where id = ?  ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppMessageRecord.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppMessageRecord appMessageRecord) {
        if (appMessageRecord!=null && appMessageRecord.getId() != null && appMessageRecord.getId() > 0) {
            this.update(appMessageRecord);
        } else {
            appMessageRecord.setId(this.add(appMessageRecord));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_message_record where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    public AppMessageRecord getOne() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_message_record where 1=1 and state = 1 ");
        sbStr.append(" order by createtime desc limit 1");
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppMessageRecord.class);
    }

    /**
     * 查询列表
     */
    public List<AppMessageRecord> list() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_message_record where 1=1 and state = 1 ");
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppMessageRecord.class);
    }
}
